package com.gizwits.akka

import scala.concurrent.{Promise, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Success, Failure, Random}


object FutureDemo {
  case class TaxCut(reduction: Int)
  def redeemCampaignPledge(): Future[TaxCut] = {
    val p = Promise[TaxCut]()
    Future {
      println("Starting the new legislative period.")
      Thread.sleep(1000)
      p.success(TaxCut(20))
      println("We reduced the taxes! You must reelect us!!!!1111")
    }
    p.future
  }
  def  show(mesg:String):Future[String]=Future{
    println("1234.....")
    Thread.sleep(Random.nextInt(2000))
    println("1234")
    s"show method{$mesg}"
  }

  def main(args: Array[String]) {

      val s=  show("feel")
      s.onComplete{
        case Failure(e)=>e.printStackTrace()
        case Success(line)=>println(line+"====")
      }

    redeemCampaignPledge()
    Thread.sleep(2000)
    println("......")



  }

}
